import request from '../tools/index.js'

// 获取商品分类
export function getColumn (params) {
  return request.get('/pro/column', { params })
}

// 根据分类获取对应品牌信息
export function getColumnBrand (params) {
  return request.get('/pro/columnBrand', { params })
}

// 根据商品分类和商品品牌获取对应品牌
export function getColumnBrandList (params) {
  return request.get('/pro/columnBrandList', { params })
}

export function sendCode (params) {
  return request.get('/user/sendMsg', { params })
}

// 注册时post方法，发送数据是直接发送键值对
export function register (params) {
  return request.post('/user/register', params)
}

export function login (params) {
  return request.get('/user/login', { params })
}

// 根据用户id获取个人信息
export function getUserMsg (params) {
  return request.get('/user/getUser', { params })
}

// 根据用户id设置要修改的信息
export function setUserMsg (params) {
  return request.post('/user/setUser', params)
}

export function getBanner () {
  return request.get('/banner')
}

export function getPro () {
  return request.get('/pro')
}

export function getcolumnImg () {
  return request.get('/pro/columnImg')
}

// 获取商品详情
export function getDetail (params) {
  return request.get('/pro/one', { params })
}

export function getCart (params) {
  return request.get('/cart', { params })
}

export function updateCartNum (params) {
  return request.post('/cart/updateNum', params)
}

export function delCart (params) {
  return request.post('/cart/del', params)
}

export function updateFlag (params) {
  return request.post('/cart/updateFlag', params)
}

export function updateAllFlag (params) {
  return request.post('/cart/updateAllFlag', params)
}

// 获取订单
export function getOrder (params) {
  return request.get('/order', { params })
}

// 添加订单
export function addOrder (params) {
  return request.post('/order/add', params)
}

// 加入购物车
export function addCart (params) {
  return request.post('/cart/add', params)
}

// 修改订单
export function pay (params) {
  return request.post('/order/pay', params)
}

// 获取单个订单详情
export function getOrderDetail (params) {
  return request.get('/order/detail', { params })
}

// 获取地址
export function getAddress (params) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve([{
        id: '1',
        name: '张三',
        tel: '13000000000',
        address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
        isDefault: true
      }])
    }, 1000)
  })
}
// 获取优惠券
export function getCoupon (params) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve({
        available: 1,
        condition: '无使用门槛\n最多优惠12元',
        reason: '',
        value: 150,
        name: '优惠券名称',
        startAt: 1489104000,
        endAt: 1514592000,
        valueDesc: '1.5',
        unitDesc: '元'
      })
    }, 1000)
  })
}

// 获取历史记录
export function getSearch (params) {
  return request.get('/search', { params })
}

// 设置历史记录
export function addSearch (params) {
  return request.post('/search/add', params)
}

// 删除历史记录
export function delSearch (params) {
  return request.post('/search/del', params)
}
